home *** CD-ROM | disk | FTP | other *** search
- Path: news.iag.net!news
- From: jatmon@iag.net (John R Buchan)
- Newsgroups: comp.lang.c
- Subject: Re: Comma Delimited function wanted
- Date: 12 Jan 1996 20:33:06 GMT
- Organization: Internet Access Group, Orlando, Florida
- Message-ID: <4d6gi2$g4r@news.iag.net>
- References: <4d1l42$mb6@voyager.Internex.NET> <4d4gic$p7u@umbc9.umbc.edu>
- NNTP-Posting-Host: pm1-orl25.iag.net
- X-Newsreader: WinVN 0.99.7
-
- In article <4d4gic$p7u@umbc9.umbc.edu>, schlein@umbc.edu says...
- <snip>
- >#include <stdio.h>
- >
- >int main (void)
- >{
- > char *buffer = "3740067099,914885AC2,P03,5000";
- > char field1[20],
- > field2[20],
- > field3[20],
- > field4[20];
- >
- > sscanf (buffer, "%[^,],%[^,],%[^,],%s", field1, field2, field3, field4);
- > printf ("field1 = %s\n", field1);
- > printf ("field2 = %s\n", field2);
- > printf ("field3 = %s\n", field3);
- > printf ("field4 = %s\n", field4);
- >
- > return (0);
- >}
-
- This works fine, unless it runs into something like:
-
- char *buffer = "3740067099,,P03,5000";
-
- A strtok based solution will have a similar problem. A full solution to
- this type of parsing will require a non-standard function (custom code).
-
- --
- John R Buchan -:|:- Looking for that elusive FAQ? ftp to:
- jatmon@mail.iag.net -:|:- rtfm.mit.edu /pub/usenet-by-group/....
-
-